﻿using System;
using Dapper;

namespace SilenthinkService
{
    internal static partial class SqlTemplate
    {
        internal static SqlBuilder.Template GetById(int id, string table)
        {
            var builder = new SqlBuilder()
                .Field("*")
                .Table(table)
                .Where("[Id]=@Id", new { id });
            return builder.AddTemplate(BasicSingleTableSqlTemplate.SelectTopOne);
        }
        internal static SqlBuilder.Template GetById(long id, string table)
        {
            var builder = new SqlBuilder()
                .Field("*")
                .Table(table)
                .Where("[Id]=@Id", new { id });
            return builder.AddTemplate(BasicSingleTableSqlTemplate.SelectTopOne);
        }
        internal static SqlBuilder.Template GetById(Guid id, string table)
        {
            var builder = new SqlBuilder()
                .Field("*")
                .Table(table)
                .Where("[Id]=@Id", new { id });
            return builder.AddTemplate(BasicSingleTableSqlTemplate.SelectTopOne);
        }
        internal static void CheckIndexSize(ref  int index, ref int size)
        {
            if (index < 1)
            {
                index = 1;
            }
            if (size < 0 || size > 200)
            {
                size = 20;
            }
        }
        internal static class DatabaseSchema
        {
            internal static class BaseSchema
            {
                internal static class Table
                {
                    internal static readonly string EmailAccount = "[EmailAccount]";
                    internal static readonly string EmailTemplate = "[EmailTemplate]";
                    internal static readonly string Bank = "[Bank]";
                    internal static readonly string EBank = "[EBank]";
                    internal static readonly string PaymentPlatform = "[PaymentPlatform]";
                }
            }
            internal static class PassportSchema
            {
                internal static class Table
                {
                    internal static readonly string User = "[User]";
                    internal static readonly string UserExtra = "[UserExtra]";
                    internal static readonly string UserProfile = "[UserProfile]";

                    internal static readonly string UserAccount = "[UserAccount]";
                    internal static readonly string UserAddress = "[UserAddress]";

                    internal static readonly string PointDetail = "[PointDetail]";
                    internal static readonly string UserRecharge = "[UserRecharge]";
                    internal static readonly string OAuthConfig = "[OAuthConfig]";

                }
            }
            internal static class PassportExtraSchema
            {
                internal static class Table
                {
                }
            }
            internal static class StoreSchema
            {
                internal static class Table
                {
                    internal static readonly string ProductCategory = "[ProductCategory]";

                    internal static readonly string Product = "[Product]";
                    internal static readonly string ProductExtra = "[ProductExtra]";
                    internal static readonly string ProductVariant = "[ProductVariant]";

                    internal static readonly string ProductAttribute = "[ProductAttribute]";

                    internal static readonly string ProductAttributeName = "[ProductAttributeName]";
                    internal static readonly string ProductAttributeValue = "[ProductAttributeValue]";

                    internal static readonly string Discount = "[Discount]";
                    internal static readonly string DiscountRequirement = "[DiscountRequirement]";
                    internal static readonly string DiscountProductCategoryMapping = "[DiscountProductCategoryMapping]";
                    internal static readonly string DiscountProductVariantMapping = "[DiscountProductVariantMapping]";
                    internal static readonly string DiscountUsageHistory = "[DiscountUsageHistory]";

                    internal static readonly string ProductAdvisory = "[ProductAdvisory]";
                    internal static readonly string ProductReview = "[ProductReview]";



                }
            }
            internal static class ExtraSchema
            {
                internal static class Table
                {
                    internal static readonly string Location = "[Location]";
                    internal static readonly string HelpQuestion = "[HelpQuestion]";
                    internal static readonly string RegisterLog = "[RegisterLog]";
                    internal static readonly string SmsValidateLog = "[SmsValidateLog]";
                    internal static readonly string EmailValidateLog = "[EmailValidateLog]";
                }
            }
            internal static class LogSchema
            {
                internal static class Table
                {
                    internal static readonly string AppError = "[AppError]";
                }
                internal static class Procedure
                {
                    internal static readonly string AddAppError = "[AppError.Add]";
                }
            }
            internal static class OrderSchema
            {
                internal static class Table
                {
                    internal static readonly string Order = "[Order]";
                    internal static readonly string OrderItem = "[OrderItem]";
                    internal static readonly string OrderTrade = "[OrderTrade]";
                    internal static readonly string OrderNote = "[OrderNote]";
                }
            }

            internal static class AuctionSchema
            {
                internal static class Table
                {
                    internal static readonly string Auction = "[Auction]";
                    internal static readonly string Bidding = "[Bidding]";
                }
            }

        }
    }
}